
package common.packet;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Received by clients when the client with name name logs out. Since the
 * username is unique it is enough to identify a client.
 * 
 * @author xissburg
 */
public class ClientOut implements Packet
{
    private String name;

    public ClientOut() {
        this("");
    }

    public ClientOut(String name) {
        this.name = name;
    }

    public ClientOut(DataInputStream in) throws IOException
    {
        this();
        read(in);
    }

    public ClientOut(ClientOut clientOut) {
        this(clientOut.getName());
    }
    
    public void read(DataInputStream in) throws IOException
    {
        name = in.readUTF();
    }

    public void write(DataOutputStream out) throws IOException
    {
        out.writeUTF(getCode().name());
        out.writeUTF(name);
    }

    public Code getCode() {
        return Code.CLIENT_OUT;
    }

    public ClientOut copy() {
        return new ClientOut(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
